package com.example.spring.demo.controller;

import com.example.spring.demo.common.error.CustomException;
import com.example.spring.demo.common.error.ErrorCodeEnum;
import com.example.spring.demo.entity.User;
import com.example.spring.demo.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/24 21:53
 **/
@Slf4j
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
public class TestController {
    private final UserService userService;

    @GetMapping(value = "/{id}", produces = "application/json")
    public User getUserById(@PathVariable int id) {
        log.info("根据id获取用户信息");
        return userService.getUserById(id);
    }

    @GetMapping("/customException")
    public String triggerCustomException() {
        throw new CustomException(ErrorCodeEnum.TEST_CUSTOM_ERROR);
    }
    @GetMapping("/unCatchException")
    public String unCatchException() {
        int i = 1 / 0;
        return "";
    }

}
